package com.ruoyi.web.controller.system.pay.controller;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.system.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author zy
 */
@Controller
public class PayController {
    @Autowired
    PayService payService;

    @GetMapping("/pay")
    public String payIndex() {
        return "pay";
    }

    @ResponseBody
    @PostMapping("/recharge")
    @RepeatSubmit
    public String recharge(@RequestParam Map<String, String> dataMap) {
        Assert.notEmpty(dataMap, "非法参数");
        Assert.notNull(dataMap.get("cardNumber"), "非法参数");
        Assert.notNull(dataMap.get("type"), "非法参数");
        boolean result = payService.pay(dataMap);
        return result ? "充值成功,请在主页刷新数据!" : "未知异常";
    }
}

